package sis.studentinfotest;/*
* @auther 顶风少年 
* @mail dfsn19970313@foxmail.com
* @date 2019-08-01 15:28
* @notify 
* @version 1.0
*/

import junit.framework.TestCase;
import sis.studentinfo.Account;

import java.math.BigDecimal;

public class MultithreadedAccountTest extends TestCase {

    public void testConcurrency()throws Exception{
        final Account account = new Account();
        account.credit(new BigDecimal("100.00"));

        Thread t1 = new Thread(new Runnable() {
            @Override
            public void run() {
                account.withdraw(new BigDecimal("80"));
            }
        });

        Thread t2  = new Thread(new Runnable() {
            @Override
            public void run() {
                account.withdraw(new BigDecimal("80"));
            }
        });

        t1.start();
        t2.start();
        t1.join();
        t2.join();

        assertEquals(new BigDecimal("20.00"),account.getBalance());
    }
}
